package com.hfplm.lhh.handler;

import java.util.Map;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

import com.teamcenter.rac.aif.AbstractAIFUIApplication;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentProcess;
import com.teamcenter.rac.kernel.TCComponentTask;
import com.teamcenter.rac.kernel.TCSession;

public class TaskInfoHandler extends AbstractHandler{
	private TCSession session;
	private AbstractAIFUIApplication app;
	InterfaceAIFComponent target;
	@Override
	public Object execute(ExecutionEvent arg0) throws ExecutionException {
		app = AIFUtility.getCurrentApplication();
		session = (TCSession)app.getSession();
		target = app.getTargetComponent();
		if(!(target instanceof TCComponentItemRevision)) {
			return null;
		}
		TCComponentItemRevision revision = (TCComponentItemRevision) target;
		
		try {
			TCComponentProcess process = revision.getCurrentJob();
			TCComponentTask rootTask = process.getRootTask();
			for(TCComponentTask task : rootTask.getSubtasks()) {
				System.out.println(task.getProperty("comments"));
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
